package com.xxx.yuedong.mine.controller;

import cn.hutool.json.JSONUtil;
import com.xxx.yuedong.common.R;
import com.xxx.yuedong.mine.controller.form.SearchRolePermissionInfoForm;
import com.xxx.yuedong.mine.controller.form.SearchRolePermissionListForm;
import com.xxx.yuedong.mine.controller.form.UpdateRolePermissionForm;
import com.xxx.yuedong.mine.service.RolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;

@RequestMapping("/role_permission")
@Api(tags = "角色权限相关相关接口")
@Slf4j
@RestController
public class RolePermissionController {
    @Autowired
    private RolePermissionService rolePermissionService;

    @PostMapping("/list")
    @ApiOperation("分页查询角色权限")
    public R list(@Valid @RequestBody SearchRolePermissionListForm form){
        HashMap param = JSONUtil.parse(form).toBean(HashMap.class);
        return rolePermissionService.list(param);
    }

    @PostMapping("/searchRolePermissionInfo")
    @ApiOperation("查询角色权限")
    public R searchRolePermissionInfo(@Valid @RequestBody SearchRolePermissionInfoForm form){
        return rolePermissionService.SearchRolePermissionInfo(form.getRoleId());
    }

    @PostMapping("/update")
    @ApiOperation("查询角色权限")
    public R update(@Valid @RequestBody UpdateRolePermissionForm form){
        return rolePermissionService.update(form);
    }
}
